package com.mmall.concurrency.example.sync;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class SynchronizedExample2 {
	
	//修饰一个类
	public static void test1(int j) {
		synchronized (SynchronizedExample2.class) {
			for(int i=0;i<10;i++) {
				log.info("test1-{}-{}",j,i);
			}
		}
	}
	
	//修饰一个静态方法
	public static synchronized void test2(int j) {
		for(int i=0;i<10;i++) {
			log.info("test2-{}-{}",j,i);
		}
	}
	
	public static void main(String args[]) {
		
		ExecutorService executorService = Executors.newCachedThreadPool();
		executorService.execute(()->{
			SynchronizedExample2.test1(1);
		});
		executorService.execute(()->{
			SynchronizedExample2.test1(2);
		});
	}
}


